package com.fancy.learncenter.fragment;


import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fancy.learncenter.adapter.FragPagerAdapter;
import com.superservice.lya.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class ToothFragment extends Fragment {
    @Bind(R.id.tabs)
    TabLayout tabs;
    @Bind(R.id.viewPager)
    ViewPager viewPager;

    FragPagerAdapter mAdapter;
    List<Fragment> fragments = new ArrayList<>();
    List<String> titles = new ArrayList<>();
    @Bind(R.id.title)
    TextView title;

    public ToothFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_tooth, container, false);
        ButterKnife.bind(this, view);
        title.setText("牙医圈");
        initView();
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    private void initView() {
        titles.add("帖子");
        titles.add("问答");
        titles.add("关注");
        titles.add("附近的人");
        fragments.add(new ToothTZFragment());
        fragments.add(new ToothWDFragment());
        fragments.add(new ToothGZFragment());
        fragments.add(new ToothFJFragment());
        mAdapter = new FragPagerAdapter(getFragmentManager(), fragments, titles);
        //设置 NestedScrollView 的内容是否拉伸填充整个视图，
        //这个设置是必须的，否者我们在里面设置的ViewPager会不可见
        viewPager.setAdapter(mAdapter);
        tabs.setupWithViewPager(viewPager);
    }

}
